<template>
  <fieldset>
    <legend>Tab切换</legend>
    <button
      v-for="(btn, index) in buttons"
      :key="index"
      @click="activeBtn = btn"
      :class="['tab-button', { active: activeBtn === btn }]"
    >
      {{ btn }}
    </button>
    <div :is="dynamic" class="tab"></div>
    <!-- <h1>{{msg}}</h1> -->
  </fieldset>
</template>
<script>
import email from "./email";
import mine from "./mine";
import charge from "./charge";
import home from "./home";
export default {
  inject: ["msg"],
  data() {
    return {
      buttons: ["Email", "Mine", "Charge", "Home"],
      activeBtn: "Email",
    };
  },
  computed: {
    dynamic() {
      return "tab-" + this.activeBtn;
    },
  },
  components: {
    "tab-Email": email,
    "tab-Mine": mine,
    "tab-Charge": charge,
    "tab-Home": home,
  },
};
</script>
<style scoped>
.tab-button {
  padding: 6px 10px;
  border-top-left-radius: 3px;
  border-top-right-radius: 3px;
  border: 1px solid #ccc;
  cursor: pointer;
  background: #f0f0f0;
  margin-bottom: -1px;
  margin-right: -1px;
}

.tab-button:hover {
  background: #e0e0e0;
}

.tab-button.active {
  background: hotpink;
}

.tab {
  border: 1px solid #ccc;
  padding: 10px;
}

h1 {
  margin: 0;
}
</style>
